<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<html>
<head>
	<title>新增</title>
	<%@ include file="/WEB-INF/views/mis/common_inc.jsp"%>
</head>
<style>
</style>
<body style="width:100%;height:90%;overflow-x:hidden;overflow-y:auto">
	<form id="addForm" class="layui-form"  method="post" > 
		 
#foreach( $field in $fieldList )
#if( $field.isPk != "Y"&&${field.inputType}!="none"&&${field.inputType}=="hidden")
            <input type="hidden"  name="${field.field}"   value="${${model.modelL}.${field.field}}"/>
#end
#if( $field.isPk != "Y"&&${field.inputType}!="hidden"&&${field.inputType}!="none")
                    <div class="layui-form-item" style="width:80%;margin-top: 2%;">
                        <label class="layui-form-label" style="font-size: 14px;">#if(!$field.nullable)#end${field.comment}：</label>
                         <div class="layui-input-block">
#if(${field.inputType}=="input")
                        <input type="text"  name="${field.field}" placeholder="请输入${field.comment}" #if($field.validate=="mobile")lay-verify="phone"#elseif($field.validate=="email")lay-verify="email"#elseif($field.validate=="url")lay-verify="url"#elseif($field.validate=="identity")lay-verify="identity"#elseif(!$field.nullable)lay-verify="required"#end value="${${model.modelL}.${field.field}}" class="layui-input" />
#elseif(${field.inputType}=="textarea")
                         <textarea class="layui-textarea"  style="height:100px;width:100%;padding:5px;overflow:auto" name="${field.field}"  placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end>${${model.modelL}.${field.field}}</textarea>
#elseif(${field.inputType}=="htmleditor")
                       <script id="editor" name="content" type="text/plain" style="width:100%;height:500px;">
                              ${${model.modelL}.${field.field}}
						</script>
#elseif(${field.inputType}=="checkbox")
                        <input class="layui-input"  type="checkbox"  name="${field.field}" placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end  value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="radio")
                        <input class="layui-input"  type="radio"  name="${field.field}" placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end  value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="date")
                       <input name="${field.field}" type="text" class="layui-input"  #if(!$field.nullable)lay-verify="required"#end placeholder="请选择日期" onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD'})" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd" />'/>
#elseif(${field.inputType}=="datetime")
                       <input name="${field.field}" type="text" class="layui-input"  #if(!$field.nullable)lay-verify="required"#end placeholder="请选择时间" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd HH:mm:ss" />'/>
#elseif(${field.inputType}=="file")
						<img alt=""  id="${field.field}_headImgArea" src="${path}/static/images/uplode.jpg" onclick="${field.field}_upload();" style="cursor:pointer;width:300px;height:150px;">
                        <input id="${field.field}_headPic" name="file" type="file" style="display:none" onchange="${field.field}_ajaxFileUploadPic(this)">
                        <!-- <span>建议上传宽高比为10:7的图片，如：1000px*700px</span> -->
                        <input id="${field.field}" name="${field.field}" type="hidden"> 
#elseif(${field.inputType}=="select")
#if("$!field.inputValueOne" == "")
                        <select name="${field.field}" style="display: none;" #if(!$field.nullable)lay-verify="required"#end  lay-search="">
							<option value="">==请选择${field.comment}==</option>
							<my:outOptions code="${field.inputValue}" value="${${model.modelL}.${field.field}}"/>
						</select>
#else
						<select id="${field.field}" name="${field.field}" style="display: none;" #if(!$field.nullable)lay-verify="required"#end  lay-search="">
							<option value="">==请选择${field.comment}==</option>
							<c:forEach items="${${field.inputValueOneL}EntityList}" var="item">
							<option value="${ item.code}" <c:if test="${ item.code==${model.modelL}.${field.field}}">selected = "selected"</c:if>>${ item.${field.inputValueTwo}}</option>
							</c:forEach>
						</select>
#end
#end
                        </div>
                   </div>
#end
#end
		 
		<div class="btn-div" style="text-align: center;margin-top: 20px;margin-bottom: 20px;">
			<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		 
		</div>
	</form>
	

<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引，用于关闭当前弹窗
 
var url= "${path}/${model.modelL}/saveAdd"; 	
 
layui.use('form', function(){
	  var form = layui.form();
	  form.render('select');
	   form.render('checkbox');
	  //监听提交
	  form.on('submit(formDemo)', function(data){
	    $.post(url,$("#addForm").serialize(),function(d){
			d=$.parseJSON(d);
	 
			parent.layer.close(index);//关闭弹窗
			parent.doSearch_dg();//刷新父页面
			layer.msg(d.message);
	        
		});
	    return false;
	  });
	});
	
#foreach( $field in $fieldList )
#if(${field.inputType}=="file")	
function ${field.field}_upload(){
	document.getElementById("${field.field}_headPic").click();
}
function ${field.field}_ajaxFileUploadPic(a) {
	
	var imgId=$(a).attr("id");
	 $("#${field.field}_headImgArea").attr("src","${path}/static/images/loading.gif");

	$.ajaxFileUpload({  
        url:'${path}/imgUpload/upload',  
        secureuri:false,  
        fileElementId:imgId,//file标签的id  
        dataType: 'json',//返回数据的类型  
        data:{id:"/single"},//一同上传的数据   
        success: function (data, status) 
        {
			 //var imgurl=window.location.protocol+"//"+window.location.host+"/resource/"+data.obj.savePath;
			 var imgurl="/resource/"+data.obj.savePath;
			 $("#${field.field}_headImgArea").attr("src",imgurl);
			 $("#${field.field}").val(imgurl);
			 
		},
		error : function(data, status, e)//服务器响应失败处理函数  
	    {  
			alert("图片上传失败，请重试一下！");
			$("#${field.field}_headImgArea").attr("src","${path}/static/images/uplode.jpg");
	    } 
    });
	return false;
}
#end
#end
</script>
</body>
</html>